package com.doit.mr.day06;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;


/**
 * @DATE 2021/12/8/14:51
 * @Author MDK
 * @Version 2021.2.2
 **/
public class NoReducer {
    static class NoReducerMapper extends Mapper<LongWritable, Text, Text, NullWritable>{
        Text k = new Text();

        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            String str = value.toString().toUpperCase();
            k.set(str);
            context.write(k,NullWritable.get());
        }
    }

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf,"no_reducer");
        job.setMapperClass(NoReducerMapper.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        FileInputFormat.setInputPaths(job,new Path("d://aaa//1.txt"));
        FileOutputFormat.setOutputPath(job, new Path("d://aaa//no_reducer"));
        job.waitForCompletion(true);
    }
}
